package com.zut.edu;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.qmuiteam.qmui.layout.QMUIFrameLayout;
import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.qmuiteam.qmui.skin.QMUISkinHelper;
import com.qmuiteam.qmui.skin.QMUISkinManager;
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.QMUIViewPager;
import com.qmuiteam.qmui.widget.popup.QMUIFullScreenPopup;
import com.qmuiteam.qmui.widget.popup.QMUIPopup;
import com.qmuiteam.qmui.widget.popup.QMUIPopups;
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder;
import com.qmuiteam.qmui.widget.tab.QMUITabIndicator;
import com.qmuiteam.qmui.widget.tab.QMUITabSegment;
import com.zut.edu.fragment.FragmentAdapter;
import com.zut.edu.fragment.QueryRecordFirstFragment;
import com.zut.edu.fragment.QueryRecordSecondFragment;
import com.zut.edu.fragment.QueryRecordThirdFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class QueryRecordActivity extends AppCompatActivity {
    @BindView(R.id.queryrecord_topbar)
    QMUITopBarLayout queryrecordtopBar;
    @BindView(R.id.query_search_layout)
    QMUILinearLayout querysearchlayout;
    @BindView(R.id.tabs)
    QMUITabSegment mTabSegment;
    @BindView(R.id.qm_view_pager)
    QMUIViewPager mContentViewPager;
    @BindView(R.id.query_edittext)
    EditText queryedittext;
    private ContentPage mDestPage = ContentPage.Item1;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_queryrecord);
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);//沉浸式
        initTopBar();
        initTabAndPager();

    }
    private void initTopBar(){
        querysearchlayout.setRadius(50);
        queryedittext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(QueryRecordActivity.this, SearchActivity.class);
                startActivity(intent);
            }
        });
        queryrecordtopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    private void initTabAndPager() {
        int indicatorHeight = QMUIDisplayHelper.dp2px(this, 2);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new QueryRecordFirstFragment());
        fragments.add(new QueryRecordSecondFragment());
        FragmentAdapter adapter = new FragmentAdapter(fragments, getSupportFragmentManager());
        mContentViewPager.setAdapter(adapter);
        mContentViewPager.setSwipeable(false);//取消侧滑
        mContentViewPager.setCurrentItem(mDestPage.getPosition(), false);
        QMUITabBuilder builder = mTabSegment.tabBuilder();
        mTabSegment.setIndicator(new QMUITabIndicator(indicatorHeight, false, false));
        mTabSegment.setBackgroundColor(Color.parseColor("#69615E"));
        mTabSegment.addTab(builder.setText("追溯记录").setColor(getResources().getColor(R.color.qmui_config_color_gray_6),getResources().getColor(R.color.qmui_config_color_white)).build(this));
        mTabSegment.addTab(builder.setText("特别关注").setColor(getResources().getColor(R.color.qmui_config_color_gray_6),getResources().getColor(R.color.qmui_config_color_white)).build(this));
        mTabSegment.setupWithViewPager(mContentViewPager, false);
        mTabSegment.setMode(QMUITabSegment.MODE_FIXED);
        mTabSegment.addOnTabSelectedListener(new QMUITabSegment.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int index) {
            }

            @Override
            public void onTabUnselected(int index) {

            }

            @Override
            public void onTabReselected(int index) {
            }

            @Override
            public void onDoubleTap(int index) {
                mTabSegment.clearSignCountView(index);
            }
        });
    }

    public enum ContentPage {
        Item1(0),
        Item2(1);
        public static final int SIZE = 2;
        private final int position;

        ContentPage(int pos) {
            position = pos;
        }

        public static ContentPage getPage(int position) {
            switch (position) {
                case 0:
                    return Item1;
                case 1:
                    return Item2;
                default:
                    return Item1;
            }
        }

        public int getPosition() {
            return position;
        }
    }

}
